package com.qing.expert.modules.expert.controller;

import com.qing.expert.common.annotation.OperationLog;
import com.qing.expert.common.response.R;
import com.qing.expert.modules.expert.service.ExpertRatingService;
import com.qing.expert.modules.expert.vo.response.ExpertRatingVO;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/expert/ratings")
public class ExpertRatingController {

    @Resource
    private ExpertRatingService expertRatingService;

    /**
     * 获取达人评价列表
     */
    @GetMapping("/{expertId}")
    public R<List<ExpertRatingVO>> getRatingList(@PathVariable String expertId) {
        return R.ok(expertRatingService.getRatingList(expertId));
    }

    /**
     * 提交评价
     */
    @OperationLog(action = "submit_rating", detail = "提交评价")
    @PostMapping("/orders/{orderId}")
    public R<Void> submitRating(
            @PathVariable String orderId,
            @RequestParam Integer rating,
            @RequestParam String comment,
            HttpServletRequest request) {
        String userId = (String) request.getAttribute("userId");
        expertRatingService.submitRating(userId, orderId, rating, comment);
        return R.ok();
    }

    /**
     * 获取达人评分
     */
    @GetMapping("/{expertId}/score")
    public R<Double> getExpertRating(@PathVariable String expertId) {
        return R.ok(expertRatingService.getExpertRating(expertId));
    }
}